package hu.kisprof.quiz.view.panels;

import hu.kisprof.quiz.model.bean.Statistic;
import hu.kisprof.quiz.view.Labels;
import hu.kisprof.quiz.view.QuizGUI;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.util.Iterator;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class QuizPlayerStatsPanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2478076081461156944L;
	private QuizGUI gui;
	private JLabel usernameLabel;
	private JScrollPane statsScrollPane;
	
	
	
	
	
	
	
	
	public QuizPlayerStatsPanel(String username, QuizGUI gui){
		super(new BorderLayout());
		this.gui = gui;
		
		
		changeUser(username);
	}








	public void changeUser(String username){
		if (username!=null && username!=""){
			this.removeAll();
			
			JPanel usrnamePanel = new JPanel(new GridLayout(2,1));
			
			usernameLabel=new JLabel(Labels.user+" :");
			usernameLabel.setFont(new Font(usernameLabel.getFont().getFontName(),Font.BOLD,20));
			usrnamePanel.add(usernameLabel);
			usernameLabel=new JLabel(username);
			usernameLabel.setFont(new Font(usernameLabel.getFont().getFontName(),Font.BOLD,18));
			usrnamePanel.add(new JLabel(username));
			this.add(usrnamePanel, BorderLayout.NORTH);
			
			List<Statistic> stats = gui.getControl().getPlayerStats(username);
			Iterator<Statistic> it = stats.iterator();
			
			JPanel statsPanel = new JPanel(new GridLayout(stats.size(),1));
			
			while (it.hasNext()){
				Statistic stat = it.next();
				JPanel holdingPanel = new JPanel();
				holdingPanel.add(new JLabel(stat.getName()+": "));
				holdingPanel.add(new JLabel(stat.getValue()));
				statsPanel.add(holdingPanel);
				
			}
			statsScrollPane = new JScrollPane(statsPanel);
			statsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
			JPanel tmpJPanel = new JPanel(new BorderLayout());
			tmpJPanel.add(statsScrollPane, BorderLayout.NORTH);
			this.add(tmpJPanel, BorderLayout.CENTER);
			this.validate();
		}
	}
}
